﻿/******************************************************************
** 文 件 名: Bud_Category_MDL.cs
** Copyright (c) 2007-2008 广东东方思维科技有限公司
** 创 建 人: gxl
** 创建日期: 2008-9-3 19:58:52
** 描    述: Bud_Category的实体类
** 版    本: 1.0.0.1
** 修改描述:
** 修 改 人:
** 修改日期:
******************************************************************/
using System;
using System.Collections.Generic;
using System.Text;


using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
using OT.Module.ModelConst;
using OT.Common;
using OT.EntLib.Validate;

namespace OT.Module.Model
{
    [Serializable]
    [Persistent(GDB.Category), OptimisticLocking(false)]
    public partial class Category : XPLiteObject
    {
        #region ~

        /// <summary>
        /// 构造函数
        /// </summary>
        public Category() : base ( new Session() )
        {

        }

        public Category(Session s)
            : base(s)
        {
        }

        public Category(Session s, XPClassInfo info)
            : base(s, info)
        {
        }

        #endregion

        #region ID

        private string _ID = "";
        /// <summary>
        /// 
        /// </summary>
        /// 
        [Key(false)]
        public string ID
        {
            get
            {
                return _ID;
            }
            set
            {
                SetPropertyValue("ID", ref _ID, value);
            }
        }
        #endregion

        #region ChildCategorys  子分类集合

        [Association("Category-Categorys", typeof(Category))]
        public XPCollection<Category> ChildCategorys { get { return GetCollection<Category>("ChildCategorys"); } }

        #endregion

        #region ParentCategory  父分类

        private Category _ParentCategory;

        [Association("Category-Categorys")]
        public Category ParentCategory
        {
            get
            {
                return _ParentCategory;
            }
            set
            {
                SetPropertyValue("ParentCategory", ref _ParentCategory, value);
            }
        }

        #endregion

        #region Name  分类名称
        
        private string _Name = "";

        [StringLengthValidator( GConst.NameMinLen , GConst.NameMaxLen,
           MessageTemplate = MsgUtility.StringLength )]
        [NotNullValidator(MessageTemplate = MsgUtility.NotNull, Tag = GSyntax.Category.Name)]
        [DisplayName(GSyntax.Category.Name), Size(GConst.NameMaxLen)]
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                SetPropertyValue("Name", ref _Name, value);
            }
        }

        #endregion

        #region OrderNo 排序号

        private int _orderNo = 0;

        [RangeValidator(0, RangeBoundaryType.Inclusive, Int32.MaxValue , RangeBoundaryType.Inclusive,
          MessageTemplate = MsgUtility.IntRangeEqualBetween, Tag = GSyntax.Category.OrderNo)]
        [DisplayName(GSyntax.Category.OrderNo)]
        public int OrderNo
        {
            get
            {
                return _orderNo;
            }
            set
            {
                SetPropertyValue("OrderNo", ref _orderNo, value);
            }
        }

        #endregion

        #region Stamp  时间戳

        private byte[] _Stamp;

        [NonPersistent]
        public byte[] Stamp
        {
            get
            {
                return _Stamp;
            }
            set
            {
                _Stamp = value;
            }
        }

        #endregion

        #region ParentCategoryID  父分类ID

        [NonPersistent]
        public string ParentCategoryID
        {
            get
            {
                string ret = "";
                if (ParentCategory != null)
                    ret = ParentCategory.ID;
                return ret;
            }
            set
            {
                ParentCategory = Session.GetObjectByKey<Category>(value);
            }
        }

        #endregion 
    }
}

